package com.voxel.sense.infomsg.broad;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.example.com.common.utils.L;
import com.example.com.common.utils.NetworkUtils;

import org.greenrobot.eventbus.EventBus;

import cyy.example.com.facotry.constants.EventBusConstants;
import cyy.example.com.facotry.model.EventEntity;

/**
 * Created by ChenYiYao on 2018/10/8.
 * des : 监听网络变化广播
 */
public class NetBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            //网络状态发生变化
            boolean connected = NetworkUtils.isConnected();
            L.d("网络状态改变--CONNECTIVITY_ACTION");
            if (connected) {
                //网络可用
                EventBus.getDefault().post(new EventEntity(EventBusConstants.NETWORK_AVAILABLE, ""));
            } else {
                //网络不可用
                EventBus.getDefault().post(new EventEntity(EventBusConstants.NETWORK_UNAVAILABLE, ""));
            }
        }
    }
}
